﻿using Geometry;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UserInterface.Primitives;

namespace UserInterface.Tests.Primitives
{
    [TestClass]
    public class GridTests
    {
        [TestMethod]
        public void Grid_ScrollBar_Test()
        {
            Grid grid = new Grid();
            grid.Rows.Add(new GridBand() { Unit = GridBandUnit.Auto });
            grid.Rows.Add(new GridBand() { Unit = GridBandUnit.Percent, Length = 1f });
            grid.Rows.Add(new GridBand() { Unit = GridBandUnit.Auto });

            // This should be percent
            grid.Columns.Add(new GridBand() { Unit = GridBandUnit.Percent, Length = 1f });

            var topArrow = new ContentStub(new Size(16, 16));
            Grid.Row.SetValue(topArrow, 0);
            grid.Children.Add(topArrow);

            var track = new ContentStub(new Size(16, 16));
            Grid.Row.SetValue(track, 1);
            grid.Children.Add(track);

            var bottomArrow = new ContentStub(new Size(16, 16));
            Grid.Row.SetValue(bottomArrow, 2);
            grid.Children.Add(bottomArrow);

            grid.Measure(new Size(100, 100), null);

            Assert.AreEqual(new Size(100f, float.PositiveInfinity), topArrow.MeasureSize);
            Assert.AreEqual(new Size(100f, 68f), track.MeasureSize);
            Assert.AreEqual(new Size(100f, float.PositiveInfinity), bottomArrow.MeasureSize);

            Assert.AreEqual(new Size(16f, 48f), grid.DesiredSize);
            
            grid.Arrange(new Rect(100, 100, 116, 200), null);

            Assert.AreEqual(new Rect(0f, 0f, 16f, 16f), topArrow.ArrangedRect);
            Assert.AreEqual(new Rect(0f, 16f, 16f, 84f), track.ArrangedRect);
            Assert.AreEqual(new Rect(0f, 84f, 16f, 100f), bottomArrow.ArrangedRect);
        }
    }
}
